﻿using RuPeng.ThriftTest1.Contract;
using System;
using System.Collections.Generic;
using Thrift.Protocol;
using Thrift.Transport;

namespace ThriftTest1.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            using (TTransport transport = new TSocket("localhost", 8801))
            using (TProtocol protocol = new TBinaryProtocol(transport))
            using (var clientUser = new UserService.Client(protocol))
            {
                transport.Open();
                User u = clientUser.Get(1);
                Console.WriteLine($"{u.Id},{u.Name},{u.Age}");
                List<User> list = clientUser.GetAll();
                Console.WriteLine($"{list[0].Id},{list[0].Name},{list[0].Age},{list[0].Remark}");
                Console.WriteLine($"{list[1].Id},{list[1].Name},{list[1].Age},{list[1].Remark}");
                Console.WriteLine("Finish");
                
                SaveResult rs1 = clientUser.Save(new User(112233, "name11try", 112233));
                Console.WriteLine("执行结果" + rs1);
                SaveResult rs2 = clientUser.Save(new User(332211, "name11tryagain", 332211));
                Console.WriteLine("执行结果" + rs2);
                SaveResult r3 = clientUser.Save(new User(332211, "ERROR", 332211));
                Console.WriteLine("执行结果" + r3);

                Console.ReadLine();
            }
        }
    }
}
